#include"Cirquenue.hpp"
#include<pthread.h>
#include<unistd.h>
void* Produce(void* args)
{
    Circular_queue<int>* q=static_cast<Circular_queue<int>*>(args);
    int in=0;
    while(1)
    {
        q->Equeue(in);
        std::cout<<"生产了一个数据:"<<in<<std::endl;
        in++;
    }
}
void* Consum(void* args)
{
    Circular_queue<int>* q=static_cast<Circular_queue<int>*>(args);
    int out;
    sleep(1);
    while(1)
    {
        q->Pop(out);
        std::cout<<"消费了一个数据:"<<out<<std::endl;
        sleep(1);
    }
}

void text1()
{
    Circular_queue<int>* mytext=new Circular_queue<int>();
    pthread_t c1;
    pthread_t c2;
    //pthread_t c3;
    //pthread_t c4;
    pthread_t p1;
    pthread_t p2;
    //pthread_t p3;
    pthread_create(&c1,nullptr,Consum,(void*)mytext);
    pthread_create(&c2,nullptr,Consum,(void*)mytext);
    //pthread_create(&c3,nullptr,Consum,(void*)mytext);
    //pthread_create(&c4,nullptr,Consum,(void*)mytext);
    pthread_create(&p1,nullptr,Produce,(void*)mytext);
    pthread_create(&p2,nullptr,Produce,(void*)mytext);
    //pthread_create(&p3,nullptr,Produce,(void*)mytext);
    pthread_join(c1,nullptr);
    pthread_join(c2,nullptr);
    //pthread_join(c3,nullptr);
    //pthread_join(c4,nullptr);
    pthread_join(p1,nullptr);
    pthread_join(p2,nullptr);
    //pthread_join(p3,nullptr);
}
int main()
{
    text1();
    return 0;
}
